#include "Affix.h"
#include "Effect.h"

#include "Exceptions.h"

Affix::Affix(std::string affixName, Effect* affixMGEF, const Soulgem& affixSoul) : name(affixName), mgef(affixMGEF), soul(&affixSoul) {
}

string Affix::get() const {
	return name;
}

bool Affix::set(string newName) {
	mgef->souls = mgef->souls | *soul;
	name = newName;
	return true;
}

bool Affix::clr() {
	mgef->souls = mgef->souls & !*soul;
	name = "";
	return true;
}

bool Affix::getOnSelf() const {
	return mgef->getOnSelf();
}

bool Affix::setOnSelf(const bool newVal) {
	return mgef->setOnSelf(newVal);
}

bool Affix::getNoVars() const {
	return mgef->getNoVars();
}

bool Affix::setNoVars(const bool newVal) {
	return mgef->setNoVars(newVal);
}

unsigned int Affix::getMinUses() const {
	return mgef->getMinUses();
}

bool Affix::setMinUses(const unsigned int newVal) {
	return mgef->setMinUses(newVal);
}

unsigned int Affix::getMaxUses() const {
	return mgef->getMaxUses();
}

bool Affix::setMaxUses(const unsigned int newVal) {
	return mgef->setMaxUses(newVal);
}

float Affix::getNoDurChance() const {
	return mgef->getNoDurChance();
}

bool Affix::setNoDurChance(const float newVal) {
	return mgef->setNoDurChance(newVal);
}

float Affix::getMinMagPct() const {
	return mgef->getMinMagPct();
}

bool Affix::setMinMagPct(const float newVal) {
	return mgef->setMinMagPct(newVal);
}

float Affix::getMinDurPct() const {
	return mgef->getMinDurPct();
}

bool Affix::setMinDurPct(const float newVal) {
	return mgef->setMinDurPct(newVal);
}

float Affix::getRank() const {
	return mgef->getRank();
}

bool Affix::setRank(const float newVal) {
	return mgef->setRank(newVal);
}

float Affix::getFreq() const {
	return mgef->getFreq();
}

bool Affix::setFreq(const float newVal) {
	return mgef->setFreq(newVal);
}

const bool Affix::operator ==(const Affix right) const {
	if ( mgef == right.mgef )
		if ( soul == right.soul )
			if ( name == right.name )
				return true;
			else
				throw name_conflict();
		else
			return false;
	else
		throw mismatched_effects();
}

const bool Affix::operator < (const Affix right) const {
	if ( mgef == right.mgef )
		return soul < right.soul;
	else
		throw mismatched_effects();
}

const bool Affix::operator <=(const Affix right) const {
	if ( mgef == right.mgef )
		return soul <= right.soul;
	else
		throw mismatched_effects();
}

const bool Affix::operator > (const Affix right) const {
	if ( mgef == right.mgef )
		return soul > right.soul;
	else
		throw mismatched_effects();
}

const bool Affix::operator >=(const Affix right) const {
	if ( mgef == right.mgef )
		return soul >= right.soul;
	else
		throw mismatched_effects();
}

const bool Affix::operator ==(const string right) const {
	return name == right;
}

const bool operator ==(const string left, const Affix right) {
	return left == right.name;
}

const bool Affix::operator !=(const string right) const {
	return name != right;
}

const bool operator !=(const string left, const Affix right) {
	return left != right.name;
}

const bool Affix::operator < (const Soulgem& right) const {
	return *soul < right;
}

const bool operator < (const Soulgem& left, const Affix right) {
	return left < *(right.soul);
}

const bool Affix::operator <=(const Soulgem& right) const {
	return *soul <= right;
}

const bool operator <=(const Soulgem& left, const Affix right) {
	return left <= *(right.soul);
}

const bool Affix::operator > (const Soulgem& right) const {
	return *soul > right;
}

const bool operator > (const Soulgem& left, const Affix right) {
	return left > *(right.soul);
}

const bool Affix::operator >=(const Soulgem& right) const {
	return *soul >= right;
}

const bool operator >=(const Soulgem& left, const Affix right) {
	return left >= *(right.soul);
}
